package workspace.teaweb.Logistics.controllers;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import workspace.teaweb.CRM.pojo.vo.CRMVO;
import workspace.teaweb.Logistics.pojo.dto.OrderDto;
import workspace.teaweb.Logistics.pojo.entity.Logistics;
import workspace.teaweb.Logistics.pojo.vo.orderVO;
import workspace.teaweb.Logistics.service.LogisticsService;
import workspace.teaweb.User.pojo.vo.UserVO;
import workspace.teaweb.base.response.JsonResult;
import workspace.teaweb.base.response.StatusCode;
import workspace.teaweb.Logistics.mappers.OrderMapper;
import workspace.teaweb.Logistics.pojo.dto.UserOrder;
import workspace.teaweb.Logistics.pojo.entity.Order;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Validated//验证
@Slf4j
@Api(tags = "订单管理")
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    LogisticsService logisticsService;



    @ApiOperation( "员工新增订单")
    @ApiOperationSupport(order = 10)
    @PostMapping("/CRM/insertOrder")
    public JsonResult CRMinsertOrder(@RequestBody Order order,@RequestBody Logistics logistics) {
        logisticsService.CRMinsertOrder(order,logistics);
        log.debug("订单信息查询:{}",order);
        return JsonResult.ok(order);
    }

    @ApiOperation( "客户新增订单")
    @ApiOperationSupport(order = 20)
    @PostMapping("/User/insertOrder")
    public JsonResult UserinsertOrder(@RequestBody Order order) {
        System.out.println("order订单是："+order);
        logisticsService.UserinsertOrder(order);
        log.debug("订单信息查询:{}",order);
        return JsonResult.ok(order);
    }

    @ApiOperation( "员工修改订单状态")
    @ApiOperationSupport(order = 30)
    @PostMapping("/CRM/updateOrderStatus")
    public JsonResult CRMupdateOrderStatus(@RequestBody Order order) {
        logisticsService.CRMupdateOrderStatus(order);
        log.debug("订单信息查询:{}",order);
        return JsonResult.ok(order);
    }
    @ApiOperation( "客户修改订单状态")
    @ApiOperationSupport(order = 40)
    @PostMapping("/User/updateOrderStatus/{id}")
    public JsonResult UserupdateOrderStatus(@PathVariable Long id) {
        logisticsService.UserupdateOrderStatus(id);
        log.debug("订单信息查询:{}",id);
        return JsonResult.ok();
    }

    @ApiOperation( "商户修改订单状态")
    @ApiOperationSupport(order = 50)
    @PostMapping("/Admin/updateOrder")
    public JsonResult AdminupdateOrder(@RequestBody Order order) {
        logisticsService.AdminupdateOrder(order);
        log.debug("订单信息查询:{}",order);
        return JsonResult.ok(order);
    }


    @ApiOperation( "员工查询订单")
    @ApiOperationSupport(order = 60)
    @GetMapping("/CRM/selectOrderById")
    public JsonResult CRMselectOrderById(@RequestBody OrderDto order,@ApiIgnore HttpSession session) {
        CRMVO CRMVo = (CRMVO)session.getAttribute("CRM");
        List<Order> ordervo = logisticsService.CRMselectOrderById(order,CRMVo);
        log.debug("订单信息查询:{}",ordervo);
        return JsonResult.ok(ordervo);
    }
    @ApiOperation( "客户查询订单")
    @ApiOperationSupport(order = 70)
    @GetMapping("/User/selectOrderById/{id}")
    public JsonResult UserselectOrderById(@PathVariable Long id,@ApiIgnore HttpSession session) {
        UserVO userVO = (UserVO)session.getAttribute("user");
        List<orderVO> ordervo = logisticsService.UserselectOrderById(id,userVO);
        log.debug("订单信息查询:{}",ordervo);
        return JsonResult.ok(ordervo);
    }
    @ApiOperation( "商户查询订单")
    @ApiOperationSupport(order = 80)
    @GetMapping("/Admin/selectOrderById/{id}")
    public JsonResult AdminselectOrderById(@PathVariable Long id,@ApiIgnore HttpSession session) {
        UserVO userVO = (UserVO)session.getAttribute("user");

        List<orderVO> ordervo = logisticsService.AdminselectOrderById(id,userVO);
        System.out.println(ordervo);
        return JsonResult.ok(ordervo);
    }

    @ApiOperation( "商户查询订单2")
    @ApiOperationSupport(order = 80)
    @GetMapping("/Admin/selectOrderByOrderId/{orderId}")
    public JsonResult AdminselectOrderByOrderId(@PathVariable Long orderId,@ApiIgnore HttpSession session) {
        UserVO userVO = (UserVO)session.getAttribute("user");

        List<orderVO> ordervo = logisticsService.AdminselectOrderByOrderId(orderId,userVO);
        System.out.println(ordervo);
        return JsonResult.ok(ordervo);
    }
    @ApiOperation( "物流信息查询订单")
    @ApiOperationSupport(order = 90)
    @GetMapping("/selectOrderByLogisticsid")
    public JsonResult selectOrderByLogisticsid(int logisticsid) {
        Order order = logisticsService.selectOrderByLogisticsid(logisticsid);
        log.debug("订单信息查询:{}",order);
        return JsonResult.ok(order);
    }


}
